const { defineConfig } = require("@vue/cli-service");
const PrerenderSPAPlugin = require("prerender-spa-plugin-next");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const path = require("path");
const resolve = dir => path.join(__dirname, dir)
module.exports = defineConfig({
  configureWebpack: {
    resolve: {
      alias:{
        '@': resolve('./src'),
        'cpt': resolve('./src/components'),
        'view': resolve('./src/view')
      }
    },
    plugins: [
      // new UglifyJsPlugin({
      //   uglifyOptions: {
      //     output: {
      //       comments: false, // 去掉注释
      //     },
      //     warnings: false,
      //     compress: {
      //       drop_console: true,
      //       drop_debugger: false,
      //       pure_funcs: ["console.log"], //移除console
      //     },
      //   },
      //   sourceMap: false,
      //   parallel: true,
      // }),
      // https://www.cnblogs.com/ldld/p/14075059.html
      new PrerenderSPAPlugin({
        staticDir: resolve("/dist"), //打包的路径
        routes: [
          "/",
          "/about",
        ], //需要预渲染的url
        rendererOptions: {
          // inject: { foo: "bar" },
          // headless: true, //这个是需要的，不然打包的html没有预渲染
          renderAfterDocumentEvent: "render-event",
        },
        renderAfterTime: 5000
      })
    ],
  },
  devServer: {
    client: {
      overlay: false
    },
    proxy: { //配置跨域
      '/basic': {
        target: 'http://t.wkvips.cn', //填写请求的目标地址
        changOrigin: true, //允许跨域
        pathRewrite: {
          // '^/basic': '' //请求的时候使用这个api就可以
        }
      }
    }
  }
})
